<template>
    <h2>显示页面</h2>

    项目名称:<input type="text" v-model="I_Name" id="I_Name">
    投资总金额:<input type="text" v-model="I_Budget_1" id="I_Budget_1">-
    <input type="text" v-model="I_Budget_2" id="I_Budget_2">
    <input type="button" value="查询" @click="Showss">

    <table class="table" border="1">
        <thead>
            <tr>
                <td>投资编号</td>
                <td>投资名称</td>
                <td>投资总额度</td>
                <td>已投资额度</td>
                <td>剩余额度</td>
                <td>投资人数</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in data" :key="item.I_Id">
                <td>{{ item.I_Id }}</td>
                <td>{{ item.I_Name }}</td>
                <td>{{ item.I_Budget.toFixed(2) }}CNY</td>
                <td>{{ item.I_Reback.toFixed(2) }}CNY</td>
                <td>{{ item.I_Receive.toFixed(2) }}CNY</td>
                <td>{{ item.I_Num }}</td>
                <td>
                    <input type="button" value="删除" @click="Del(item.I_Id)">
                    <input type="button" value="修改" @click="Upa(item.I_Id)">
                </td>
            </tr>
        </tbody>
    </table>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import axios from 'axios';



const data = ref([{
    I_Id: 0,
    I_Name: '',
    I_Budget: 0,
    I_Receive: 0,
    I_Reback: 0,
    I_Num: 0,
}])
//钩子函数 显示
onMounted(() => {
    axios.get('http://localhost:46407/api/Demo/Show')
        .then(res => {
            data.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
})
//查询
const Showss = () => {
    axios.get('http://localhost:46407/api/Demo/Showss', {
        params: {
            I_Name: I_Name.value,
            I_Budget_1: I_Budget_1.value,
            I_Budget_2: I_Budget_2.value


        }
    })
        .then(res => {
            data.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
}
//删除
const Del = (I_Id: number) => {
    if (confirm("确定要删除吗?")) {
        axios.get('http://localhost:46407/api/Demo/Del', {
            params: {
                I_Id: I_Id
            }
        })
            .then(res => {
                if (res.data > 0) {
                    alert("删除成功");
                    Showss()
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
    }
}
//传值
const route = useRouter();
const Upa = (I_Id: number) => {
    route.push({
        name: "InsertUpa",
        params: {
            I_Id: I_Id
        }
    })
}


</script>